﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Demos.DesignPatterns._12_享元模式
{
    /// <summary>
    /// 享元工厂
    /// </summary>
    public class ParticleFactory
    {
        private Dictionary<string, ParticleType> _particleTypes = new ();

        public ParticleType GetParticleType(string texture, string color)
        {
            var key = $"{texture}_{color}";
            if (!_particleTypes.ContainsKey(key))
            {
                _particleTypes[key] = new ParticleType(texture, color);
                Console.WriteLine($"创建新粒子类型: {key}");
            }
            return _particleTypes[key];
        }

    }
}
